package com.wjk.kylin.modules.system.log.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wjk.kylin.core.utils.SecurityUtils;
import com.wjk.kylin.modules.system.log.entity.OperateLog;
import com.wjk.kylin.modules.system.log.mapper.LogMapper;
import com.wjk.kylin.modules.system.log.service.ILogService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Arrays;
import java.util.Date;


/**
 * <p>
 *  日志表 服务实现类
 * </p>
 *
 * @author wangjkui
 * @since 2020-06-05
 */
@Service
@Transactional(readOnly=true)
public class LogServiceImpl extends ServiceImpl<LogMapper, OperateLog> implements ILogService {

    @Override
    public IPage<OperateLog> findPage(Page<OperateLog> page, OperateLog operateLog) {
        return baseMapper.findPage(page,operateLog);
    }

    @Override
    @Transactional(readOnly = false)
    public boolean save(OperateLog operateLog) {
        operateLog.setCreateBy(StringUtils.isNotBlank(SecurityUtils.getUsername())?SecurityUtils.getUsername():operateLog.getCreateBy());
        operateLog.setCreateDate(new Date());
        return super.save(operateLog);
    }

    @Override
    @Transactional(readOnly = false)
    public boolean deleteByIds(String[] operateLogIds) {
        return super.removeByIds(Arrays.asList(operateLogIds));
    }

    @Override
    @Transactional(readOnly = false)
    public void clean() {
        baseMapper.clean();
    }
}
